import { getUrlParam } from '@/utils/base';
export const getClientAuth = async (type = 1) => {
  return new Promise((resolve, reject) => {
    if (getUrlParam('xxf')) {
      console.log('获取到参数xxf，重新客户端发送授权请求。。');
      const { ipcRenderer } = window.require('electron');
      // 向客户端随机发送消息， 1 登录授权， 2 重新授权
      ipcRenderer.sendToHost(JSON.stringify({ type }));
      // 等待客户端回复授权用户和内容
      ipcRenderer.on('xsc-stored-user', (e, message) => {
        console.log('监听到xsc-stored-user', message);
        resolve(message);
      });
    } else {
      reject();
    }
  });
};

// 监听客户端发送的路由变化
export const listenClientRouteChange = (callback = () => {}) => {
  if (getUrlParam('xxf')) {
    const { ipcRenderer } = window.require('electron');
    ipcRenderer.on('xsc-router-jump', (e, path) => {
      console.log('监听到xsc-router-jump', path);
      callback(path);
    });
  }
};
